<?php
/**
 * Created by PhpStorm.
 * User: xiaomeng
 * Date: 17-9-14
 * Time: 下午3:39
 */

namespace app\websocket\controller;

use swf\core\Controller;

class Index extends Controller
{
    private $allow_msg = ['userOpenId','token'];
    /**
     * 首次进入游戏，初始化
     */
    public function index()
    {
        $reqData = $this->reqData;

        //判断发送的内容是否正确
        $reqKeys = array_keys($reqData);
        $res = array_intersect($reqKeys,$this->allow_msg);
        if(empty($res))
        {
            return $this->send('error',[],10);
        }

        $data['fd'] = $this->frame->fd;
        $data['userOpenId'] = $reqData['userOpenId'];
        $data['userId'] = $reqData['userId'];//后期去掉
        $data['token'] = $reqData['token'];
        $data['channelId'] = isset($reqData['channelId'])?$reqData['channelId']:'000000000000000';
        $data['type'] = isset($reqData['type'])?$reqData['type']:'user';
        $this->server->task(json_encode(['cmd'=>'init','data'=>$data]));
        return true;
    }
}